package com.lagou.niancheng.lagouservicecode.controller;

import com.lagou.niancheng.lagou.service.common.EmailDTO;
import com.lagou.niancheng.lagou.service.common.Result;
import com.lagou.niancheng.lagou.service.common.ResultBuilder;
import com.lagou.niancheng.lagouservicecode.service.CodeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * com.lagou.niancheng.lagouservicecode.controller.CodeController
 *
 * @author wlz
 * @date 2020/12/22
 */
@RestController
@RequestMapping("/code")
@Api("验证码接口")
public class CodeController {

    @Resource
    private CodeService codeService;

    @PostMapping("/create")
    @ApiOperation("发送验证码")
    public Result generateCode(@RequestBody EmailDTO emailDTO) {
        codeService.generateVerifyCode(emailDTO.getEmail());
        return ResultBuilder.toSuccess(null);
    }

    @PostMapping("/validate/{email}/{code}")
    @ApiOperation("判断验证码")
    public Result<Boolean> checkVerifyCode(@PathVariable("email") String email,
                                           @PathVariable("code") String verifyCode) {
        return ResultBuilder.toSuccess(codeService.checkVerifyCode(email, verifyCode));
    }
}
